// Copyright 2008 web2me.dev
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package net.web2me.api;

import java.io.IOException;
import java.net.MalformedURLException;

import net.web2me.parser.ClubLezParser;
import net.web2me.parser.ImageBeaverParser;
import net.web2me.parser.ImageFapParser;
import net.web2me.parser.StandardParser;
import net.web2me.parser.TerraFotologParser;
import net.web2me.parser.UbbiFotologParser;

import org.apache.log4j.Logger;

/**
 * Creates {@link Parsable} implementations
 * 
 * @author web2me
 * 
 */
public class ParserFactory {

	private static Logger logger = Logger.getLogger(ParserFactory.class);

	/**
	 * Returns the correct parser according to the configuration file
	 * 
	 * @param id
	 *            The parser name
	 * @return An instance of IParser
	 * @throws ParserFactoryException
	 * @throws IOException
	 * @throws ParserException
	 * @throws MalformedURLException
	 * @throws MalformedURLException
	 */
	public static Parsable getParser(String id) throws ParserException {
		logger.info("Looking for parser \"" + id + "\"");
		
		if (ParsersNamesConstants.CLUBLEZ.equals(id)) {
			return new ClubLezParser();
		} else if (ParsersNamesConstants.IMAGEBEAVER.equals(id)) {
			return new ImageBeaverParser();
		} else if (ParsersNamesConstants.IMAGEFAP.equals(id)) {
			return new ImageFapParser();
		} else if (ParsersNamesConstants.STANDARD.equals(id)) {
			return new StandardParser();
		} else if (ParsersNamesConstants.TERRA_FOTOLOG.equals(id)) {
			return new TerraFotologParser();
		} else if (ParsersNamesConstants.UBBI_FOTOLOG.equals(id)) {
			return new UbbiFotologParser();
		}
		
		throw new ParserException("The parser \"" + id + "\" could not be found");
	}
	
	public static Parsable[] getAllParsers() {
		return new Parsable[] {
				new ClubLezParser(),
				new ImageBeaverParser(),
				new ImageFapParser(),
				new StandardParser(),
				new TerraFotologParser(),
				new UbbiFotologParser()
		};
	}

}
